﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.mediator;
using SharpSqlAnalyzer.pp.mediator.type;
using SharpSqlAnalyzer.pp.processor.type.comm;
using SharpSqlAnalyzer.pp.utils;
using SharpSqlAnalyzer.stmt;

namespace SharpSqlAnalyzer.pp.processor.type.select
{
	// Token: 0x02000231 RID: 561
	public class UnionProcessor : AbstractProcessor
	{
		// Token: 0x060012CC RID: 4812 RVA: 0x0031A87C File Offset: 0x00318A7C
		public override void process(TParseTreeNode nodeArg)
		{
			TSelectSqlStatement tselectSqlStatement = nodeArg as TSelectSqlStatement;
			if (tselectSqlStatement.RightStmt != null && tselectSqlStatement.LeftStmt != null)
			{
				TSourceToken tsourceToken = SourceTokenSearcher.backforwardSearch(tselectSqlStatement.RightStmt.startToken, 5, "union");
				if (tsourceToken != null)
				{
					TSourceToken tsourceToken2 = null;
					TSelectSqlStatement tselectSqlStatement2 = tselectSqlStatement;
					while (tselectSqlStatement2 != null && tsourceToken2 == null)
					{
						tsourceToken2 = tselectSqlStatement2.SelectToken;
						tselectSqlStatement2 = tselectSqlStatement2.LeftStmt;
					}
					if (tsourceToken2 == null)
					{
						return;
					}
					int num = SourceTokenOperator.curColumnNumberVT(tsourceToken2);
					KeywordAlignMediator mediator = MediatorFactory.getMediator<KeywordAlignMediator>(typeof(KeywordAlignMediator), this.Option.sessionId);
					if (mediator.getLevelIndentLen(mediator.CurrentIndentLevel + 1) > num)
					{
						num = mediator.getLevelIndentLen(mediator.CurrentIndentLevel + 1);
					}
					mediator.addIndentLevelItem(tsourceToken, num);
					SourceTokenOperator.removeWhitespaceAndReturnFromEnd(this.Option, tsourceToken);
					SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createReturnSourceToken());
					SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createWhitespaceSourceToken(num));
					SourceTokenOperator.removeWhitespaceAndReturnFromEnd(this.Option, tselectSqlStatement.RightStmt.startToken);
					SourceTokenOperator.addBefore(this.Option, tselectSqlStatement.RightStmt.startToken, SourceTokenOperator.createReturnSourceToken());
					SourceTokenOperator.addBefore(this.Option, tselectSqlStatement.RightStmt.startToken, SourceTokenOperator.createWhitespaceSourceToken(num));
				}
			}
		}
	}
}
